<template>
  <div>
    <EditDiv :text.sync="content" />
    <button @click="insertAtCursorPosition">在光标位置插入内容</button>
  </div>
</template>

<script>
import EditDiv from "../components/EditDiv.vue";

export default {
  components: {
    EditDiv,
  },
  data() {
    return {
      content: "这是可编辑的内容",
      cursorPosition: 0,
    };
  },
  methods: {
    saveCursorPosition(position) {
      this.cursorPosition = position;
    },
    insertAtCursorPosition() {
      const content = this.content;
      const before = content.slice(0, this.cursorPosition);
      const after = content.slice(this.cursorPosition);
      this.content = before + "插入的内容" + after;
    },
  },
};
</script>
